<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增积分增加申请')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-apply-add" action="add" method="post">
            <div class="form-group">    
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <select id="type" name="type" class="form-control m-b" th:with="type=${@dict.getType('coin_apply_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">用户: </label>
                <div class="col-sm-8">
                    <select id="memberId" name="memberId" class="form-control m-b" required>
                        <option value="">无</option>
                        <option th:each="member : ${userList}" th:text="${member.username}+'-'+${member.mobile}+'-'+${member.frameNo}" th:value="${member.id}"></option>
                    </select>
                    <div id="tjMember"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">所属门店：</label>
                <div class="col-sm-8">
                    <select id="dealerId" name="dealerId" class="form-control m-b"  >
                        <option th:each="dict : ${dealerList}" th:text="${dict.name}" th:value="${dict.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" id="show_price">
                <label class="col-sm-3 control-label">金额：</label>
                <div class="col-sm-8">
                    <input id="price" name="price" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group" id="show_total">
                <label class="col-sm-3 control-label">智通币数量：</label>
                <div class="col-sm-8">
                    <input id="total" name="total" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea id="notes" name="notes" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12 col-sm-offset-3">
                    <button type="button" onclick="sub()" class="btn btn-primary">提交</button>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">

        function sub(){

            var type = $("#type  option:selected").text();
            var str="";
            if(type != ''){
                str =str + '类型:'+type+'<hr>';
            }
            var memberId = $("#memberId option:selected").text();
            if(memberId != ''){
                str = str+ '用户:'+memberId+'<hr>';
            }
            var dealerId = $("#dealerId option:selected").text();
            if(dealerId != ''){
                str = str+ '门店:'+dealerId+'<hr>';
            }
            var price = $("#price").val();
            if(price != ''){
                str = str+ '金额:'+price+'<hr>';
            }
            var total = $("#total").val();
            if(total != ''){
                str = str+ '智通币数量:'+total+'<hr>';
            }
            var notes = $("#notes").val();
            if(notes != ''){
                str = str+ '备注:'+notes+'<hr>';
            }
            var a = true;
            layer.confirm('确认提交吗',{
                shade:[0.5,'#000'],
                shift:1,
                shadeClose:true,
                btn:['确认','取消'],
                content:str,
                yes: function (index,layero) {
                    if(a){
                        $("form").submit();
                        layer.load(0, {
                            shade: false,
                            time: 10*1000
                        });
                        a=false;
                    }
                },btn2: function (index,layero) {
                }
            })
        }



        $("#memberId").on("change",function(){
            if($("#type").val()==11){
                $.ajax({
                    url : ctx+"system/member/parentinfo/"+$(this).val(),
                    type : "get",
                    success : function(result) {
                        if(result.data!=null){
                            $("#tjMember").html("推荐人:"+result.data.username+"  车架号:"+result.data.frameNo);
                        }else{
                            $("#tjMember").html("暂无推荐人");
                        }
                    }
                });
            }
        })


        $("#show_total").hide();
        $("#price").val("");
        $("#show_price").hide();
        $("#type").on("change",function(){
            switch ($(this).val()){
                case "11":
                    $("#total").val("");
                    $("#show_total").hide();
                    $("#price").val("");
                    $("#show_price").hide();
                    if($("#memberId").val()!=''){
                        $.ajax({
                            url : ctx+"system/member/parentinfo/"+$("#memberId").val(),
                            type : "get",
                            success : function(result) {
                                if(result.data!=null){
                                    $("#tjMember").html("推荐人:"+result.data.username+"  车架号:"+result.data.frameNo);
                                }else{
                                    $("#tjMember").html("暂无推荐人");
                                }
                            }
                        });
                    }
                    break;
                case "13":
                    $("#show_total").show();
                    $("#total").val("600");
                    $("#total").attr("readonly","readonly")
                    $("#price").val("");
                    $("#show_price").hide();
                    $("#tjMember").html("")
                    break;
                case "14":
                    $("#show_total").show();
                    $("#total").val("2000");
                    $("#total").attr("readonly","readonly")
                    $("#price").val("");
                    $("#show_price").hide();
                    $("#tjMember").html("")
                    break;
                case "19":
                    $("#show_total").show();
                    $("#total").val("10000");
                    $("#total").attr("readonly","readonly")
                    $("#price").val("");
                    $("#show_price").hide();
                    $("#tjMember").html("")
                    break;
                case "20":
                    $("#show_total").show();
                    $("#total").val("10000");
                    $("#total").attr("readonly","readonly")
                    $("#price").val("");
                    $("#show_price").hide();
                    $("#tjMember").html("")
                    break;
                default:
                    $("#show_total").show();
                    $("#show_price").show();
                    $("#price").val("");
                    $("#total").removeAttrs("readonly");
                    $("#total").val("")
                    $("#tjMember").html("")
                    break;
            }
        });

        $("#price").blur(function () {
            var price= $("#price").val();
            $("#total").val(price)
        })

    </script>
</body>
</html>